﻿package mortal.game.view.copy.crossMainCity.mainCityPosition
{
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.crossMainCity.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class MainCityAppointSmallWin extends SmallWindow
    {
        private var _bg:GBitmap;
        private var _txtMemberName:GTextFiled;
        private var _radioBtnMaster:GRadioButton;
        private var _radioBtnDeputyMaster:GRadioButton;
        private var _radioBtnPresbyter:GRadioButton;
        private var _radioBtnLaw:GRadioButton;
        private var _posNameList:Array;
        private var _btnAppoint:GButton;
        private var _isLoadComplete:Boolean = false;
        private var _info:SGuildMember;
        private static var _instance:MainCityAppointSmallWin = null;

        public function MainCityAppointSmallWin(param1:ILayer = null)
        {
            this._posNameList = [];
            super(param1);
            setSize(280, 285);
            title = Language.getString(21403);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_3:GButton = null;
            super.createDisposedChildrenImpl();
            this.addEvents();
            this._bg = UIFactory.gBitmap("", 15, 33, this);
            var _loc_1:* = GlobalStyle.textFormatJiang;
            _loc_1.size = 14;
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(60082), 63, 44, 35, 22, this, _loc_1));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(60083) + " :", 200, 44, 35, 22, this, _loc_1));
            var _loc_2:* = Language.getString(21404);
            this._txtMemberName = UIFactory.gTextField(_loc_2, 95, 44, 105, 22, this, null, true);
            this._txtMemberName.configEventListener(TextEvent.LINK, this.getPlayerInfo);
            this._txtMemberName.autoSize = "center";
            _loc_1.bold = true;
            var _loc_4:int = 0;
            while (_loc_4 < 4)
            {
                
                _loc_3 = UIFactory.gButton(Language.getString(35214), 150, 82 + 26 * _loc_4, 100, 28, this, "GreenLinkButtonSize14");
                this._posNameList.push(_loc_3);
                switch(_loc_4)
                {
                    case 0:
                    {
                        this._radioBtnMaster = UIFactory.radioButton("", 70, 82 + 26 * _loc_4, 100, 28, this);
                        this._radioBtnMaster.value = EMainCityPosition._EMainCityMarshal;
                        this._radioBtnMaster.groupName = "appointGroup";
                        this._radioBtnMaster.setStyle("textFormat", _loc_1);
                        this._radioBtnMaster.setStyle("disabledTextFormat", _loc_1);
                        this._radioBtnMaster.textField.filters = [FilterConst.glowFilter];
                        this._radioBtnMaster.label = MainCityCache.getPosNameByPosType(EMainCityPosition._EMainCityMarshal);
                        break;
                    }
                    case 1:
                    {
                        this._radioBtnDeputyMaster = UIFactory.radioButton("", 70, 82 + 26 * _loc_4, 100, 28, this);
                        this._radioBtnDeputyMaster.value = EMainCityPosition._EMainCityColonel;
                        this._radioBtnDeputyMaster.groupName = "appointGroup";
                        this._radioBtnDeputyMaster.setStyle("textFormat", _loc_1);
                        this._radioBtnDeputyMaster.setStyle("disabledTextFormat", _loc_1);
                        this._radioBtnDeputyMaster.textField.filters = [FilterConst.glowFilter];
                        this._radioBtnDeputyMaster.label = MainCityCache.getPosNameByPosType(EMainCityPosition._EMainCityColonel);
                        break;
                    }
                    case 2:
                    {
                        this._radioBtnPresbyter = UIFactory.radioButton("", 70, 82 + 26 * _loc_4, 100, 28, this);
                        this._radioBtnPresbyter.value = EMainCityPosition._EMainCityWarlord;
                        this._radioBtnPresbyter.groupName = "appointGroup";
                        this._radioBtnPresbyter.setStyle("textFormat", _loc_1);
                        this._radioBtnPresbyter.setStyle("disabledTextFormat", _loc_1);
                        this._radioBtnPresbyter.textField.filters = [FilterConst.glowFilter];
                        this._radioBtnPresbyter.label = MainCityCache.getPosNameByPosType(EMainCityPosition._EMainCityWarlord);
                        break;
                    }
                    case 3:
                    {
                        this._radioBtnLaw = UIFactory.radioButton("", 70, 82 + 26 * _loc_4, 100, 28, this);
                        this._radioBtnLaw.value = EMainCityPosition._EMainCityGuard;
                        this._radioBtnLaw.groupName = "appointGroup";
                        this._radioBtnLaw.setStyle("textFormat", _loc_1);
                        this._radioBtnLaw.setStyle("disabledTextFormat", _loc_1);
                        this._radioBtnLaw.textField.filters = [FilterConst.glowFilter];
                        this._radioBtnLaw.label = MainCityCache.getPosNameByPosType(EMainCityPosition._EMainCityGuard);
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                _loc_4++;
            }
            this.updatePosInfo();
            this._btnAppoint = UIFactory.gButton(Language.getString(60084), 114, 255, 67, 22, this);
            this._btnAppoint.configEventListener(MouseEvent.CLICK, this.appointHandler);
            LoaderHelp.addResCallBack(ResFileConst.guildOtherPanel, this.onResLoadComplete);
            Dispatcher.addEventListener(EventName.GuildMemberSelect, this.updateInfo);
            NetDispatcher.addCmdListener(ServerCommand.MainCityPostionInfoGet, this.updatePosInfo);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            LoaderHelp.removeResEvent(ResFileConst.guildOtherPanel, this.onResLoadComplete);
            Dispatcher.removeEventListener(EventName.GuildMemberSelect, this.updateInfo);
            NetDispatcher.removeCmdListener(ServerCommand.MainCityPostionInfoGet, this.updatePosInfo);
            this._isLoadComplete = false;
            this._bg.dispose(param1);
            this._bg = null;
            this._radioBtnMaster.dispose(param1);
            this._radioBtnMaster = null;
            this._radioBtnDeputyMaster.dispose(param1);
            this._radioBtnDeputyMaster = null;
            this._radioBtnPresbyter.dispose(param1);
            this._radioBtnPresbyter = null;
            this._radioBtnLaw.dispose(param1);
            this._radioBtnLaw = null;
            this._txtMemberName.dispose(param1);
            this._txtMemberName = null;
            this._info = null;
            this.remoevePosName();
            super.disposeImpl(param1);
            return;
        }// end function

        private function remoevePosName() : void
        {
            var _loc_1:GButton = null;
            for each (_loc_1 in this._posNameList)
            {
                
                _loc_1.dispose();
            }
            this._posNameList.length = 0;
            return;
        }// end function

        private function updatePosInfo(param1:Object = null) : void
        {
            var _loc_2:String = null;
            var _loc_3:GButton = null;
            var _loc_4:SMainCityPositon = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            while (_loc_6 < this._posNameList.length)
            {
                
                _loc_3 = this._posNameList[_loc_6];
                _loc_5 = 5 - _loc_6 - 1;
                _loc_3.name = _loc_5.toString();
                _loc_4 = Cache.instance.mainCity.getPostionByPosType(_loc_5);
                if (_loc_4)
                {
                    _loc_3.label = "(" + _loc_4.officer.name + ")";
                    _loc_3.enabled = true;
                    _loc_3.configEventListener(MouseEvent.CLICK, this.checkOfficerInfo);
                }
                else
                {
                    _loc_3.label = "(" + Language.getString(41365) + ")";
                    _loc_3.enabled = false;
                    _loc_3.removeEventListener(MouseEvent.CLICK, this.checkOfficerInfo);
                }
                _loc_6++;
            }
            return;
        }// end function

        private function checkOfficerInfo(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            var _loc_3:SMainCityPositon = null;
            if (event)
            {
                _loc_2 = int(event.target.name);
                _loc_3 = Cache.instance.mainCity.getPostionByPosType(_loc_2);
                if (_loc_3)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.LookPlayerInfo, _loc_3.officer.entityId));
                }
            }
            return;
        }// end function

        private function appoint() : void
        {
            GameProxy.guild.postionOper(Cache.instance.role.entityInfo.entityId.id, this._info.miniPlayer, this._radioBtnMaster.group.selection.value as int);
            return;
        }// end function

        private function closeAlert(param1:int) : void
        {
            if (param1 == Alert.OK)
            {
                this.appoint();
            }
            return;
        }// end function

        private function appointHandler(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            var _loc_3:SMainCityPositon = null;
            var _loc_4:String = null;
            var _loc_5:String = null;
            if (this._info && this._radioBtnMaster.group.selection)
            {
                _loc_2 = this._radioBtnMaster.group.selection.value as int;
                _loc_3 = Cache.instance.mainCity.getPostionByEntityId(this._info.miniPlayer.entityId);
                _loc_4 = "";
                if (_loc_3)
                {
                    if (_loc_3.positon == EMainCityPosition._EMainCityKing)
                    {
                        MsgManager.showRollTipsMsg(Language.getString(21405), MsgRollTipsType.msgRollTips3);
                        return;
                    }
                    if (_loc_3.positon == _loc_2)
                    {
                        MsgManager.showRollTipsMsg(Language.getString(21406));
                        return;
                    }
                    _loc_5 = MainCityCache.getPosNameByPosType(_loc_3.positon);
                    _loc_4 = Language.getStringByParam(21407, _loc_3.officer.name, _loc_5);
                    Alert.isFlowMouse = true;
                    Alert.show(_loc_4, null, Alert.OK | Alert.CANCEL, null, this.closeAlert, null, 4);
                    return;
                }
                _loc_3 = Cache.instance.mainCity.getPostionByPosType(_loc_2);
                if (_loc_3 && EntityUtil.equal(_loc_3.officer.entityId, Cache.instance.role.entityInfo.entityId))
                {
                    _loc_5 = MainCityCache.getPosNameByPosType(_loc_2);
                    _loc_4 = Language.getStringByParam(21408, _loc_5, _loc_3.officer.name, this._info.miniPlayer.name);
                    Alert.isFlowMouse = true;
                    Alert.show(_loc_4, null, Alert.OK | Alert.CANCEL, null, this.closeAlert, null, 4);
                    return;
                }
                this.appoint();
            }
            else
            {
                MsgManager.showRollTipsMsg(Language.getString(21409));
            }
            return;
        }// end function

        private function getPlayerInfo(event:Event) : void
        {
            if (this._info)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.LookPlayerInfo, this._info.miniPlayer.entityId));
            }
            return;
        }// end function

        public function updateInfo(event:DataEvent) : void
        {
            this._info = event.data as SGuildMember;
            this._txtMemberName.htmlText = "<a href=\'event:memberNameLink\' target = \'\'><font color=\'#436b74\' size=\'14\'><u>" + this._info.miniPlayer.name + "</u></font></a>";
            return;
        }// end function

        public function set selectIndex(param1:int) : void
        {
            this._radioBtnMaster.group.getRadioButtonAt(4 - param1).selected = true;
            return;
        }// end function

        protected function addEvents() : void
        {
            configEventListener(MouseEvent.CLICK, this.onMouseClick);
            return;
        }// end function

        public function onMouseClick(event:MouseEvent) : void
        {
            return;
        }// end function

        protected function onResLoadComplete() : void
        {
            this._isLoadComplete = true;
            this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.guildAppointmentBg);
            return;
        }// end function

        public function get isLoadComplete() : Boolean
        {
            return this._isLoadComplete;
        }// end function

        override public function hide() : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildClose));
            super.hide();
            return;
        }// end function

        public static function get instance() : MainCityAppointSmallWin
        {
            if (!_instance)
            {
                _instance = new MainCityAppointSmallWin;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
